package cn.ecut.dzy.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @program: juc
 * @description:
 * @author: DingZhenYun
 * @create: 2021-10-19 15:00
 **/

public class ThreadPoolDemo1 {
    public static void main(String[] args) {
        //一池五线程
        ExecutorService executorService1 = Executors.newFixedThreadPool(5);
        //一池一线程
        ExecutorService executorService2 = Executors.newFixedThreadPool(1);

        //一池可扩容线程
        ExecutorService threadPool3 = Executors.newCachedThreadPool();
        try {
            for (int i = 1; i <=10; i++) {
                //执行
                threadPool3.execute(()->{
                    System.out.println(Thread.currentThread().getName()+" 办理业务");
                });
            }
        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            //关闭
            threadPool3.shutdown();
        }
    }
}
